package com.jvyou.thread.d03instance;

import java.util.concurrent.FutureTask;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/30 9:47
 * @Description
 */
public class ThreadDemo {
    public static void main(String[] args) {
        // 创建任务
        CallableImpl callable = new CallableImpl();
        // 创建 FutureTask 管理任务的结果
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        // 创建线程并启动
        Thread thread = new Thread(futureTask);
        thread.start();
        // 获取结果
        try {
            Integer result = futureTask.get();
            System.out.println("结果：" + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
